<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of article
 *
 * @author Administrator
 */
class product extends CI_Controller {

    private $page_size = 10;

    public function __construct() {
        parent::__construct();
        $this->url = $this->uri->segments;
        $this->CI = & get_instance();
    }

    public function index() {
        $this->load->library('a_product');
        $product_obj = new a_product();
        $page = isset($_GET['page'])?$_GET['page']:1;//当前页
        $data['product_list'] = $product_obj->get_product_list_page(CONFIG_ID,'','',$page,$this->page_size);
        //print_r($data['product_list']);
        $arr = array (
            'page' => $page,//当前页
            'page_size' => $this->page_size,     //分页总大小
            'total' => $data['product_list']['page']['cnt']//总记录数
        );
        $start_page = ($page-1)*$this->page_size;
        $data['pagination'] = new pagination($arr);
        $this->load->view('template_pro',$data);
    }

    public function detail($id) {
        if($id){
            $this->load->library('a_product');
            $product_obj = new a_product();
            $data['product_info'] = $product_obj->get_product($id);

            $g_nav_list = $this->CI->load->get_var('g_nav_list');//获取导航
            $info = $this->return_classid($g_nav_list,$data['product_info']['classid']);
            $data['parentid'] = $info['parentid'];

            $this->load->view('product_detail',$data);
        }else{
            redirect('cn/main/nofont');
        }
    }

    private function return_classid($nav_one=array(),$classid=''){
        if(empty($nav_one)){
            return ;
        }else{
            $return = array();
            foreach($nav_one as $k=>$v){
                if(!empty($v['child'])){
                    foreach ($v['child'] as $key => $value) {
                        if($value['classid'] == $classid){
                            $return['nav_new'] = $v['child'];
                            $return['classid'] = $value['classid'];
                            $return['parentid'] = $v['classid'];
                        }else{
                            continue;
                        }
                    }
                }else{
                    continue;
                }
            }
            return $return ;
        }
    }

}
